<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CIBlog
 *
 * 使用codeigniter框架开发的一个博客。
 * 
 * @package     ciblog
 * @author      Eric
 * @copyright   Copyright (c) 2011 - 2012, Eric
 * @license     GNU General Public License 2.0
 * @link        http://www.hebaijun.com
 * @version     1.0
 */

 //----------------------------------------------------------

 /**
  * 登陆信息控制器
  *
  * 登陆，登出，忘记密码，修改密码，新建用户等
  *
  * @package     ciblog
  * @subpackage  Controllers
  * @category    Admin Controllers
  * @author      Eric <baijun.he@163.com>
  * @link        http://www.hebaijun.com
  */
class Login extends CI_Controller {

	/**
     * 构造函数
     * 
     * @access public
     * @return void
     */
    public function __construct()
    {
		parent::__construct();

		/** 加载验证类 */
		$this->load->library('ion_auth');

		$this->load->library('session');
    }

	/**
	 * 默认方法
	 *
	 * @access   public
	 * @return   void
	 */
	public function index()
	{
		//如果已经登陆，直接跳转到后台
		if ($this->ion_auth->logged_in())
		{
			$this->session->set_flashdata('message', $this->ion_auth->messages());
			redirect('admin/admin', 'refresh');
		}

		//标题
		$data['current_title'] = $this->lang->line('default_login');

		//取得ciblog的所有设置项
		$data['bloginfo'] = $this->option_m->load_all_options();

		$data['message'] = $this->session->flashdata('message');

		$this->load->view('admin/login',$data);
	}

	/**
	 * 登陆
	 *
	 * @access   public
	 * @return   void
	 */
	public function login_submit()
	{
		$login_name =  $this->input->post('login_name', TRUE);
		$login_password =  $this->input->post('login_password', TRUE);
		$login_remeber = (bool) $this->input->post('login_remeber', TRUE);

		if ($this->ion_auth->login($login_name, $login_password, $login_remeber))
		{
			//登陆成功
			$this->session->set_flashdata('message', $this->ion_auth->messages());
			redirect('admin/admin', 'refresh');
		}
		else
		{
			//登陆失败
			$this->session->set_flashdata('message', $this->ion_auth->errors());
			redirect('admin/login', 'refresh'); 
		}
	}

	/**
	 * 登出
	 *
	 * @access   public
	 * @return   void
	 */
	function logout()
	{
		//log the user out
		$logout = $this->ion_auth->logout();

		//redirect them back to the page they came from
		redirect('admin/login', 'refresh');
	}

}

/* End of file admin.php */
/* Location: ./application/controllers/admin/admin.php */